from django.db import models
from datetime import datetime
from apps.core.models import GenericModel
from apps.users.models import Provider
from .types import (NOTIFICATION_TYPES,
                    NotificationTypes,
                    CLIENT_NOTES_REMINDER_TYPES,
                    APPOINTMENT_REMINDER_TYPES,
                    ClientNotesReminderTypes,
                    AppointmentReminderTypes, CLIENT_NOTIFICATION_TYPES, ClientNotificationTypes
                    )
from ..client.models import Client


class ProviderNotificationSetting(GenericModel):
    fcm_id = models.CharField(max_length=127, blank=True, default='')

    client_messages = models.BooleanField(default=True)
    payment_received = models.BooleanField(default=True)
    payment_overdue = models.BooleanField(default=True)
    client_check_in = models.BooleanField(default=True)
    software_updates = models.BooleanField(default=True)

    class Meta:
        db_table = 'provider_notification_settings'

    def __str__(self):
        return self.provider


class ProviderNotification(GenericModel):
    content = models.TextField(null=True, blank=True)
    datetime = models.DateTimeField(
        null=True,
        blank=True,
        default=datetime.now)
    notification_type = models.IntegerField(
        choices=NOTIFICATION_TYPES,
        default=NotificationTypes.CLIENT_CHECK_IN.value)
    read = models.BooleanField(default=False)

    class Meta:
        db_table = 'provider_notification'

    def __str__(self):
        return self.content


class ProviderReminderSetting(GenericModel):

    TWO_DAYS_BEFORE = 1
    ONE_DAY_BEFORE = 2
    ONE_HOUR_BEFORE = 3
    FIVE_MINUTES_BEFORE = 4
    SESSION_START_TIME = 5
    NONE = 6

    appointment_type_two_days_before = models.BooleanField(default=False)
    appointment_type_one_day_before = models.BooleanField(default=False)
    appointment_type_one_hour_before = models.BooleanField(default=False)
    appointment_type_five_minutes_before = models.BooleanField(default=False)
    appointment_type_session_start_time = models.BooleanField(default=False)
    appointment_type_none = models.BooleanField(default=True)

    telehealth_type_two_days_before = models.BooleanField(default=False)
    telehealth_type_one_day_before = models.BooleanField(default=False)
    telehealth_type_one_hour_before = models.BooleanField(default=False)
    telehealth_type_five_minutes_before = models.BooleanField(default=False)
    telehealth_type_session_start_time = models.BooleanField(default=False)
    telehealth_type_none = models.BooleanField(default=True)

    client_notes_type_one_month_after = models.BooleanField(default=False)
    client_notes_type_one_week_after = models.BooleanField(default=False)
    client_notes_type_one_day_after = models.BooleanField(default=False)
    client_notes_type_two_days_after = models.BooleanField(default=False)
    client_notes_type_none = models.BooleanField(default=True)

    class Meta:
        db_table = 'provider_reminder'


class ClientNotification(GenericModel):
    client = models.ForeignKey(Client, on_delete=models.CASCADE)
    content = models.TextField(null=True, blank=True)
    datetime = models.DateTimeField(
        null=True,
        blank=True,
        default=datetime.now)
    notification_type = models.IntegerField(
        choices=CLIENT_NOTIFICATION_TYPES,
        default=ClientNotificationTypes.PROVIDER_MESSAGES.value)
    read = models.BooleanField(default=False)

    class Meta:
        db_table = 'client_notification'

    def __str__(self):
        return self.client